package com.xdf.zipperdye.controller;

import com.xdf.zipperdye.utils.DynamicDBUtils;
import com.xdf.zipperdye.utils.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "动态查询")
@CrossOrigin
@RestController
@RequestMapping("/dynamicQuery")
public class DynamicQueryController {
    @Autowired
    private DynamicDBUtils dynamicDBUtils;

    @ApiOperation(value="执行查询SQL", notes="示例：http://localhost:7075/zipperdye/dynamicQuery/querySqlString/select * from bill_type", produces="application/json")
    @GetMapping("/querySqlString/{sql}")
    public JsonResult querySqlString(@PathVariable String sql){
        return JsonResult.ok(dynamicDBUtils.queryForList(sql));
    }

    @ApiOperation(value="调用存储过程进行查询", notes="传入参数格式：[\"usp_getBillType8Storage\",\"原料仓库\"]", produces="application/json")
    @PostMapping("/callProc")
    public JsonResult callProc(@RequestBody List<String> procAndParams){
        return JsonResult.ok(dynamicDBUtils.queryForListCallProc(procAndParams));
    }
}
